package com.lzh.persevere.controller;

import com.lzh.persevere.common.R;
import com.lzh.persevere.common.ResultUtil;
import com.lzh.persevere.model.entity.CategoryInfo;
import com.lzh.persevere.model.qo.PageModelQO;
import com.lzh.persevere.service.CategoryInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 文章分类controller
 *
 * @author luzhiheng
 * @since 2025-07-18
 */
@RestController
@RequestMapping("/category")
@Api(tags = "文章分类")
public class CategoryInfoController {

    @Resource
    private CategoryInfoService categoryInfoService;

    @ApiOperation(value = "分页查询分类列表")
    @PostMapping("/findCategoryPage")
    public R<Map<String, Object>> findCategoryPage(@Valid @RequestBody PageModelQO qo) {
        return ResultUtil.success(categoryInfoService.findCategoryPage(qo));
    }

    @ApiOperation(value = "查询分类列表")
    @PostMapping("/findCategoryList")
    public R<List<CategoryInfo>> findCategoryList() {
        return ResultUtil.success(categoryInfoService.list());
    }

    @ApiOperation(value = "更新分类")
    @PostMapping("/updateCategory")
    public R<Boolean> updateCategory(@Valid @RequestBody CategoryInfo categoryInfo) {
        return ResultUtil.success(categoryInfoService.updateById(categoryInfo));
    }

    @ApiOperation(value = "添加分类")
    @PostMapping("/addCategory")
    public R<Boolean> addCategory(@Valid @RequestBody CategoryInfo categoryInfo) {
        return ResultUtil.success(categoryInfoService.save(categoryInfo));
    }

    @ApiOperation(value = "删除分类")
    @PostMapping("/delCategory")
    public R<Boolean> delCategory(@Valid @RequestBody CategoryInfo categoryInfo) {
        return ResultUtil.success(categoryInfoService.removeById(categoryInfo));
    }
}
